package com.itheima.example.provider;

import com.itheima.example.common.service.UserService;
import com.itheima.weirpc.RpcApplication;
import com.itheima.weirpc.config.RegistryConfig;
import com.itheima.weirpc.config.RpcConfig;
import com.itheima.weirpc.model.ServiceMetaInfo;
import com.itheima.weirpc.registry.LocalRegistry;
import com.itheima.weirpc.registry.Registry;
import com.itheima.weirpc.registry.RegistryFactory;
import com.itheima.weirpc.server.tcp.VertxTcpServer;

/**
 * ClassName: ProviderExample
 * Package: com.itheima.example.provider
 * Description:
 *
 * @Author 看到风
 * @Create 2024/11/23 19:36
 * @Version 1.0
 */
public class ProviderExample2 {
    public static void main(String[] args) {
        //PRC 框架初始化
        RpcApplication.init();

        //注册服务
        String serviceName = UserService.class.getName();
        LocalRegistry.register(UserService.class.getName(), UserServiceImpl.class);

        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();

        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());

        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(serviceName);
        serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());
        serviceMetaInfo.setServicePort(9998);

        try {
            registry.register(serviceMetaInfo);
        }catch (Exception e){
            throw new RuntimeException(e);
        }

        //启动 web 服务
//        HttpServer httpServer = new VertxHttpServer();
//        httpServer.doStart(RpcApplication.getRpcConfig().getServerPort());

        //启动TCP服务
        VertxTcpServer vertxTcpServer = new VertxTcpServer();
        vertxTcpServer.doStart(9998);
    }
}
